package net.com.sunkey.messagehandler;

import java.nio.ByteBuffer;

import net.com.sunkey.protobuf.Protocol;
import net.com.sunkey.protobuf.NewMessageResponse.NewMessageResponseData;
import net.com.sunkey.serverlogic.Message;
import net.com.sunkey.serverlogic.Server;

/**
 * @author kohachiro
 *
 */
public class NewMessageResponseHandler {

	/**
	 * 
	 */
	//@Override
	public static int invoke(Object data, Object channel) throws Exception {
		System.out.println("["+channel.hashCode()+"]["+Protocol.MessageHandler.NewMessageResponse_VALUE+"]NewMessageResponse");
		NewMessageResponseData.Builder builder=NewMessageResponseData.newBuilder();
		builder.setMessage(((Message)data).getMessage());
		builder.setRouter(((Message)data).getRouter());
		builder.setUserid(((Message)data).getUser().getId());
		builder.setUsername(((Message)data).getUser().getName());
		NewMessageResponseData message=builder.build();
		
		Server.sendResponse(Protocol.MessageHandler.NewMessageResponse_VALUE, ByteBuffer.wrap(message.toByteArray()), channel);
		return Protocol.MessageHandler.NewMessageResponse_VALUE;
	}
}